package ch.bfh.mobicomp;

import android.app.AlarmManager;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;

public class AlarmManagerService extends Service {

	public AlarmManagerService() {
		super();
	}

	public static final String PREFS_FILENAME = "MyPrefsFile";
	public static final String PREFS_TIME = "time";

	SharedPreferences settings = getSharedPreferences(PREFS_FILENAME, 0); // 0:
																			// Permission
	SharedPreferences.Editor editor = settings.edit();

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// Log.v("UNIX Time", Long.toString(intent.getLongExtra("starttimeInMs",
		// 0)));

		long starttimeInMs = intent.getLongExtra("starttimeInMs", 0);

		if (starttimeInMs == 0) {
			starttimeInMs = settings.getLong(PREFS_TIME, starttimeInMs);
		} else {
			editor.putLong(PREFS_TIME, starttimeInMs);
		}
		
		AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
		
	
//        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
//                        firstTime, 30*1000, mAlarmSender);

        


		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

}
